	$(document).ready(function() {
		$("#resourceForm").validate({
			errorPlacement:function(error,element) {  	
				error.appendTo(element.parent().children());
			}, 
			errorElement: "em"  
		});
		
		
		  $('#summernote').summernote({
			  onImageUpload: function (files, editor, $editable) {
				  	sendFile(files[0], editor, $editable);
				  },
// 		lang:'zh-CN',
 		  height: 300,
		  toolbar: [
				['style', ['style','bold', 'italic', 'underline', 'clear']],
				['font', ['strikethrough']],
				['fontsize', ['fontsize']],
				['color', ['color']],
				['layout', ['ul', 'ol', 'paragraph']],
				['height', ['height']],
				['insert', ['link', 'picture']]
				]
		  });
		  $('#send').click(function(){
			  if(QC.Login.check()){
			  if($("#resourceForm").valid()){
				  var sHTML = $('#summernote').code();
					 $('#resourceContent').val(sHTML);
					 $.ajax({
					        data: $('#resourceForm').serializeArray(),
					        type: "POST",
					        url: ctx+"/resource",
					        dataType : "json",
//		 			        cache: false,
//		 			        contentType: false,
//		 			        processData: false,
					        success: function (data) {
					            alert(data.msg);
					        }
					    });
			  }
		  }else{
			  alert("请先登录...");
		  }
		  });
		  
	});
	
	
	$('input[type="file"]').change(function(e){
		
		var selectedFile = $('#input').get(0).files[0];
		
		alert(selectedFile);
	    data = new FormData();
		data.append("file", e);
		data.append("token","2liIyhpQX6QXv-tFS6HpWGWnAD6J4M8bRKOaDMKv:zjGSlI9tXPxicotT15kPp79N99o=:eyJzY29wZSI6InlhbmdzaiIsImRlYWRsaW5lIjozMjE2MzMyMzUwfQ==");
//		    url = ctx+"/image";
	    url="http://upload.qiniu.com/"
	    $.ajax({
	        data: data,
	        type: "POST",
	        url: url,
	        cache: false,
	        contentType: false,
	        processData: false,
	        success: function (data) {
	        	alert(data.key);
	        	if(data != ""){
//	        		editor.insertImage(welEditable,""data.key);
//	        		alert("http://7xjcjk.com1.z0.glb.clouddn.com/"+data.key);
	        		$("#pic").val("http://7xjcjk.com1.z0.glb.clouddn.com/"+data.key);
	        	}else{
	        		alert("图片上传失败");
	        	}
	            
	        }
	    });
	})
	
	
	function handleFiles(files){
		data = new FormData();
		data.append("file", files[0]);
		data.append("token","2liIyhpQX6QXv-tFS6HpWGWnAD6J4M8bRKOaDMKv:zjGSlI9tXPxicotT15kPp79N99o=:eyJzY29wZSI6InlhbmdzaiIsImRlYWRsaW5lIjozMjE2MzMyMzUwfQ==");
	    url="http://upload.qiniu.com/"
	    $.ajax({
	        data: data,
	        type: "POST",
	        url: url,
	        cache: false,
	        contentType: false,
	        processData: false,
	        success: function (data) {
	        	if(data != ""){
	        		$("#pic").val("http://7xjcjk.com1.z0.glb.clouddn.com/"+data.key);
	        	}else{
	        		alert("图片上传失败");
	        	}
	            
	        }
	    });
	}
